﻿@using System.Data
@{
    ViewBag.Title = "";
    Layout = "~/Areas/Admin/Views/Shared/AdminLayout.cshtml";
    DataSet table = ViewData["menudata"] as DataSet;
}
<style>
    * {
        overflow-y: auto;
    }
</style>
<div class="searchpanel">
    <div class="seatchtool">
        <div class="operationtool">
            <a id="edit">修改</a>
            <a id="add">增加</a>
            <a id="del">删除</a>
          
        </div>
    </div>
</div>
<table class="datatable">
    <tr>
        <th width="30">选择<input type="checkbox" id="checkall" /></th>
        <th width="100">角色名称</th>
        <th width="100">启用</th>
        <th width="200">创建人员</th>
        <th width="200">备注</th>
        <th width="100">创建时间</th>
        <th width="100">操作</th>
        <th >*</th>
    </tr>
    <tbody id="list">

    </tbody>
</table>
<div class="zhanwei"></div>
<script>

    $(function() {
        getlist();
    });



    //选择全部
    $("#checkall").click(function () {
        if ($("#checkall").attr("checked")) {
            $("#list input[type=checkbox]").attr("checked", "true");
        } else {
            $("#list input[type=checkbox]").removeAttr("checked");
        }
    });
    //删除
    $("#del").click(function () {
        if (confirm("确定删除数据吗？")) {
            var id = "";
            $("#list input[type=checkbox]").each(function () {
                if ($(this).attr("checked")) {
                    id += $(this).val() + ",";
                }
            });
            if (id == "") {
                alert("请选择要修改的数据！");
                return false;
            }
            id = id.substring(0, id.length - 1);

            $.post("@Url.Action("Del")", { ids: id }, function (row) {
                if (row > 0) {
                    getlist(0);
                } else {
                    alert("删除失败！");
                }
            });
        }
    });

    //修改
    $("#edit").click(function () {
        var id = 0;
        $("#list input[type=checkbox]").each(function () {
            if ($(this).attr("checked")) {
                id = $(this).val();
                return false;
            }
        });
        if (id == 0) {
            alert("请选择要修改的数据！");
        } else {
            location.href = "@Url.Action("Window")" + "?id=" + id;
        }
    });
    //添加
    $("#add").click(function() {
        location.href = "@Url.Action("Window", new {id = 0})";
    });

    function getlist() {
        $.post("@Url.Action("GetList")", function(data) {
            var obj = jQuery.parseJSON(data);
            var str = "";
            for (var i = 0; i < obj.length; i++) {
                var item = obj[i];
                str += "<tr>" +
                    "<td><input type=\"checkbox\"  value=" + item.Id + " /></td>" +
                    "<td>" + item.RoleName + "</td>" +
                    "<td>" + (item.IsExit == 0 ? "已启用" : "已禁用") + "</td>" +
                    "<td>" + item.UserName + "</td>" +
                    "<td>" + (item.Remark == null ? "" : item.Remark) + "</td>" +
                    "<td>" + item.Date.substring(0, 10) + "</td>" +
                    "<td><a class=\"ope_bt\" onclick='editqx(" + item.Id + ")'>权限分配</a></td>" +
                    "<td></td>" +
                    "</tr>";
            }
            $("#list").html(str);
        });
    }

    function editqx(id) {
        location.href = "@Url.Action("RoleAlloat")?id="+id;
    }
</script>